<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="https://og6593g2z.qnssl.com/fundebug.0.3.3.min.js"
            apikey="f425f662987ebb7ba8943b7db3a296603e9d5a91ad9fefd25f16a1923106bf9a"></script>
    <script src="__LAYUI__/layui.js"></script>
    <link href="__LAYUI__/css/layui.css" rel="stylesheet"/>
    <title>Title</title>
</head>
<body>

<div style="width: 100%;height: 30px">
    <div style="float: right">

        <button class="layui-btn layui-btn-normal" id="magazineInsert">新增</button>

    </div>
</div>

<table id="magazine" lay-filter="text"></table>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-danger layui-btn-mini" lay-event="del">删除</a>
</script>


<script>
    layui.use(['table', 'jquery'], function () {
        var table = layui.table
            , $ = layui.$
            ,layer = layui.layer;;


        table.render({
            elem: '#magazine'
            , page: true
            , limit: 10
            , cols: [[
                {field: 'Id', title: 'ID', width: 100},
                {field: 'name', title: '名称', width: 200},
                {field: 'circle', title: '操作周期/月', width: 150},
                {field: 'price', title: '参考价格', width: 100},
                {field: 'remark',event:'showRemark', title: '备注', width: 500},
                {fixed: 'right', width: 100, align: 'center', toolbar: '#barDemo'}
            ]]
            , id: 'magazine'
            , url: '/index/Magazine/getMagazine'
            , response: {
                statusCode: 1
            }
        });

        table.on('tool(text)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.open({
                    type: 0,
                    content: '确定删除?',
                    yes: function (index, layero) {
                        $.ajax({
                            type: 'post',
                            url: '/index/Magazine/delMagazine',
                            data: {
                                'id': data.Id
                            },
                            success: function (result) {
                                if (result.code) {
                                    layer.msg(result.msg, {
                                        icon: 1,
                                        time: 3000 //2秒关闭（如果不配置，默认是3秒）
                                    });
                                }
                                table.reload('magazine', {});
                            }
                        });

                        layer.close(index);
                    }

                });
            }
            if (obj.event === 'showRemark') {
                layer.open({
                    title:'备注',
                    offset: 't',
                    type: 0,
                    content: data.remark,
                });
            }
        });


        $('#magazineInsert').click(function () {

            layer.open({
                type: 2,
                offset: '0px',
                title: '新增期刊',
                scrollbar: false,
                resize: false,
                area: ['600px', '570px'],
                shadeClose: true,
                content: ['/index/Magazine/insertMagazine', 'no'],
            });
        });
//
//        $('#magazineDel').click(function () {
//            layer.open({
//                type: 2,
//                offset:'100px',
//                title: '删除',
//                scrollbar: false,
//                resize: false,
//                area:['900px','380px'],
//                shadeClose: true,
//                content: ['/index/Magazine/magazineMe','no'],
//                end:function () {
//                    table.reload('magazine', {});
//                }
//            });
//        });

    });
</script>

</body>
</html>